import { MessageBox } from "element-ui";

/**
 * @description 操作单条数据信息 (二次确认【删除、禁用、启用、重置密码】)
 * @param {Function} removeApi 操作数据接口的api方法 (必传)
 * @param {*} params 携带的操作数据参数
 * @param {String} message
 * @param {String} title
 * @param {Object} options
 * @returns {Promise}
 */
export function useRemoveData(
	removeApi,
	params,
	message = "确定删除所选项吗？",
	title = "提示",
	options = { type: "warning" }
) {
	return new Promise((resolve, reject) => {
		MessageBox.confirm(message, title, options)
			.then(async () => {
        const res = await removeApi(params);
        if (!res) return reject(false);
        resolve(true);
			})
	});
}

/**
 * @description 计算新页码
 * @param {Function} count 删除条数 (必传)
 * @param {Object} pagData (必传)
 * @returns {Number}
 */
export function  resetPageNum(count = 1, pagData) {
  const { pageNum, pageSize, total } = pagData;
  if ((pageNum - 1) * pageSize + count === total) {
    return pageNum - 1;
  }
  return pageNum;
}